/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */

using System;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

namespace TFrameWork.Module.ActionEditor
{
    public class TestPlayable : MonoBehaviour
    {
        public AnimationClip clip;
        
        private PlayableGraph _graph;
        private AnimUnit _animUnit;

        private void Start()
        {
            _graph = PlayableGraph.Create();

            _animUnit = new AnimUnit(_graph, clip);

            //连接输出端
            var output = AnimationPlayableOutput.Create(_graph, "Anim", GetComponent<Animator>());
            output.SetSourcePlayable(_animUnit.GetAnimAdapterPlayable());
            
            //播放
            _graph.Play();
        }

        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (_animUnit.enable)
                {
                    _animUnit.Disable();
                }
                else
                {
                    _animUnit.Enable();
                }
            }
        }
        
        private void OnDisable()
        {
            _graph.Destroy();
        }
    }
}
